﻿using _1_Interfaces.Interfaces.Cjw;
using _1_Interfaces.Models.Tables.Cjw;
using _2_Services;
using AutoMapper;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace _2_Services.Services.Cjw
{
    /// <summary>
    /// 科室管理
    /// </summary>
    public class DepartmentService : IDepartmentService
    {
        SqlSugarClient _db = CjwDbContext.GetInstance();
        private IMapper _mapper;

        public DepartmentService(IMapper mapper)
        {
            _mapper = mapper;
        }

        /// <summary>
        /// 获取科室列表
        /// </summary>
        /// <returns></returns>
        public List<DepartmentList> GetDepartmentList()
        {
            return _db.Queryable<DepartmentList>()
                .ToList();
        }

        /// <summary>
        /// 新增科室
        /// </summary>
        /// <param name="departmentList"></param>
        /// <returns></returns>
        public bool AddDepartment(DepartmentList departmentList)
        {
            if (_db.Insertable(departmentList).ExecuteCommand() == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除科室
        /// </summary>
        /// <param name="departmentId">科室id</param>
        /// <returns></returns>
        public bool DelDepartment(int departmentId)
        {
            return _db.Deleteable<DepartmentList>()
                .Where(x => x.DepartmentId == departmentId)
                .ExecuteCommandHasChange();
        }
    }
}
